package edu.szte.ovrt.datahandler.ui.console;

import java.io.*;

/**
 * Represents input item which sould be read from the user
 * 
 * @author Péter Török
 */
public final class DialogInputItem extends UIBase {

	private final String m_label;
	private final Boolean m_emptyValid;
	private String m_value = null;

	public DialogInputItem(final String label) {
		this(label, false);
	}

	public DialogInputItem(final String label, final Boolean emptyValid) {
		m_label = label;
		m_emptyValid = emptyValid;
	}

	protected Boolean read() {
		showLabel(m_label);
		final BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
		try {
			final String value = rd.readLine();
			if (value.length() == 0) { return m_emptyValid; }
			m_value = value;
			return true;
		} catch (final IOException e) {
			return false;
		}
	}

	public String getValue() {
		return m_value;
	}

}
